package com.youkeyi.ddy.cloud.application.business.hr.employee.interview.controller;

import com.youkeyi.ddy.cloud.common.api.application.business.hr.employee.interview.BusinessEmployeeInterviewRecordsCloudService;
import com.youkeyi.ddy.cloud.common.api.application.business.hr.employee.interview.dto.BusinessEmployeeInterviewRecordsListCloudDto;
import com.youkeyi.ddy.cloud.common.api.application.business.hr.employee.interview.dto.BusinessEmployeeInterviewRecordsListItemCloudDto;
import com.youkeyi.ddy.cloud.common.api.application.business.hr.employee.interview.param.BusinessEmployeeInterviewRecordsCreateCloudParam;
import com.youkeyi.ddy.cloud.common.api.application.business.hr.employee.interview.param.BusinessEmployeeInterviewRecordsDeleteCloudParam;
import com.youkeyi.ddy.cloud.common.api.application.business.hr.employee.interview.param.BusinessEmployeeInterviewRecordsListCloudParam;
import com.youkeyi.ddy.cloud.common.api.application.business.hr.employee.interview.param.BusinessEmployeeInterviewRecordsUpdateCloudParam;
import com.youkeyi.ddy.cloud.common.api.basic.hr.employee.interview.HrEmployeeInterviewRecordsCloudService;
import com.youkeyi.ddy.cloud.common.api.basic.hr.employee.interview.dto.HrEmployeeInterviewRecordsListCloudDto;
import com.youkeyi.ddy.cloud.common.api.basic.hr.employee.interview.param.HrEmployeeInterviewRecordsCreateCloudParam;
import com.youkeyi.ddy.cloud.common.api.basic.hr.employee.interview.param.HrEmployeeInterviewRecordsDeleteCloudParam;
import com.youkeyi.ddy.cloud.common.api.basic.hr.employee.interview.param.HrEmployeeInterviewRecordsQueryCloudParam;
import com.youkeyi.ddy.cloud.common.api.basic.hr.employee.interview.param.HrEmployeeInterviewRecordsUpdateCloudParam;
import com.youkeyi.ddy.cloud.common.constant.YoukeyiDdyCloudBasicPublicConstant;
import com.youkeyi.ddy.cloud.common.context.YoukeyiSystemContext;
import com.youkeyi.ddy.cloud.common.enums.ResponseCodeEnum;
import com.youkeyi.ddy.cloud.common.response.ResponseContent;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * BusinessEmployeeInterviewRecordsController
 *
 * @Author liuxiawang
 * @Date 2024/6/13 3:04 PM
 * @Location shenzhen.china
 */
@Service
public class BusinessEmployeeInterviewRecordsController implements BusinessEmployeeInterviewRecordsCloudService {

    @Autowired
    private HrEmployeeInterviewRecordsCloudService hrEmployeeInterviewRecordsCloudService;

    @Override
    public BusinessEmployeeInterviewRecordsListCloudDto list(BusinessEmployeeInterviewRecordsListCloudParam param) {
        BusinessEmployeeInterviewRecordsListCloudDto dto = new BusinessEmployeeInterviewRecordsListCloudDto();
        String corpKey = YoukeyiSystemContext.getCorpPrimaryKey();
        if (StringUtils.isBlank(corpKey)) {
            dto.setErrorMessage(ResponseCodeEnum.TOKEN_INVALID.getMessage());
            return dto;
        }
        if (null == param) {
            dto.setErrorMessage(ResponseCodeEnum.PARAMETER_ILLEGAL.getMessage());
            return dto;
        }

        HrEmployeeInterviewRecordsQueryCloudParam employeeQueryCloudParam = new HrEmployeeInterviewRecordsQueryCloudParam();
        employeeQueryCloudParam.setEmployeeInterviewRecordsPrimaryKeys(param.getEmployeeInterviewRecordsPrimaryKeys());
        employeeQueryCloudParam.setEmployeePrimaryKeys(param.getEmployeePrimaryKeys());
        employeeQueryCloudParam.setPageSize(param.getPageSize());
        employeeQueryCloudParam.setCurrentPage(param.getCurrentPage());
        HrEmployeeInterviewRecordsListCloudDto employeeDtos = hrEmployeeInterviewRecordsCloudService.query(employeeQueryCloudParam);
        if (null != employeeDtos && CollectionUtils.isNotEmpty(employeeDtos.getRows())) {
            List<BusinessEmployeeInterviewRecordsListItemCloudDto> items = new ArrayList<>();
            employeeDtos.getRows().forEach(employee -> {
                BusinessEmployeeInterviewRecordsListItemCloudDto item = new BusinessEmployeeInterviewRecordsListItemCloudDto();
                item.setEmployeeInterviewRecordsPrimaryKey(employee.getEmployeeInterviewRecordsPrimaryKey());
                item.setEmployeeKey(employee.getEmployeeKey());
                item.setStartDate(employee.getStartDate());
                item.setInterviewTime(employee.getInterviewTime());
                item.setDepartmentKey(employee.getDepartmentKey());
                item.setDepartmentName(employee.getDepartmentName());
                item.setPositionKey(employee.getPositionKey());
                item.setPositionName(employee.getPositionName());
                item.setInterviewerKey(employee.getInterviewerKey());
                item.setInterviewerName(employee.getInterviewerName());
                item.setInterviewerStatus(employee.getInterviewerStatus());
                item.setInterviewComments(employee.getInterviewComments());
                item.setAnnexKey(employee.getAnnexKey());
                item.setRemark(employee.getRemark());
                item.setIsDeleted(employee.getIsDeleted());
                item.setIsDeletedName(YoukeyiDdyCloudBasicPublicConstant.SYSTEM_YES_OR_NO.getName(item.getIsDeleted()));
                item.setCreateTime(employee.getCreateTime());
                item.setCreateUserKey(employee.getCreateUserKey());
                item.setCreateUserName(employee.getCreateUserName());
                item.setUpdateTime(employee.getUpdateTime());
                item.setUpdateUserKey(employee.getUpdateUserKey());
                item.setUpdateUserName(employee.getUpdateUserName());
                items.add(item);
            });
            dto.setRows(items);
            dto.setTotal(employeeDtos.getTotal());
        }
        dto.setSuccessMessage(ResponseCodeEnum.SUCCESS.getMessage());
        return dto;
    }

    @Override
    public ResponseContent create(BusinessEmployeeInterviewRecordsCreateCloudParam param) {
        ResponseContent rc = new ResponseContent();
        String corpKey = YoukeyiSystemContext.getCorpPrimaryKey();
        if (StringUtils.isBlank(corpKey)) {
            rc.setErrorMessage(ResponseCodeEnum.TOKEN_INVALID.getMessage());
            return rc;
        }
        if (null == param
                || StringUtils.isBlank(param.getEmployeeKey())
        ) {
            rc.setErrorMessage(ResponseCodeEnum.PARAMETER_ILLEGAL.getMessage());
            return rc;
        }

        HrEmployeeInterviewRecordsCreateCloudParam employeeCreateCloudParam = new HrEmployeeInterviewRecordsCreateCloudParam();
        employeeCreateCloudParam.setEmployeeKey(param.getEmployeeKey());
        employeeCreateCloudParam.setStartDate(param.getStartDate());
        employeeCreateCloudParam.setInterviewTime(param.getInterviewTime());
        employeeCreateCloudParam.setDepartmentKey(param.getDepartmentKey());
        employeeCreateCloudParam.setDepartmentName(param.getDepartmentName());
        employeeCreateCloudParam.setPositionKey(param.getPositionKey());
        employeeCreateCloudParam.setPositionName(param.getPositionName());
        employeeCreateCloudParam.setInterviewerKey(param.getInterviewerKey());
        employeeCreateCloudParam.setInterviewerName(param.getInterviewerName());
        employeeCreateCloudParam.setInterviewerStatus(param.getInterviewerStatus());
        employeeCreateCloudParam.setInterviewComments(param.getInterviewComments());
        employeeCreateCloudParam.setAnnexKey(param.getAnnexKey());
        employeeCreateCloudParam.setRemark(param.getRemark());
        employeeCreateCloudParam.setCreateUserKey(YoukeyiSystemContext.getUserPrimaryKey());
        employeeCreateCloudParam.setCreateUserName(YoukeyiSystemContext.getUserName());
        return hrEmployeeInterviewRecordsCloudService.create(employeeCreateCloudParam);
    }

    @Override
    public ResponseContent update(BusinessEmployeeInterviewRecordsUpdateCloudParam param) {
        ResponseContent rc = new ResponseContent();
        String corpKey = YoukeyiSystemContext.getCorpPrimaryKey();
        if (StringUtils.isBlank(corpKey)) {
            rc.setErrorMessage(ResponseCodeEnum.TOKEN_INVALID.getMessage());
            return rc;
        }
        if (null == param
                || StringUtils.isBlank(param.getEmployeeInterviewRecordsPrimaryKey())
        ) {
            rc.setErrorMessage(ResponseCodeEnum.PARAMETER_ILLEGAL.getMessage());
            return rc;
        }

        HrEmployeeInterviewRecordsUpdateCloudParam employeeUpdateCloudParam = new HrEmployeeInterviewRecordsUpdateCloudParam();
        employeeUpdateCloudParam.setEmployeeInterviewRecordsPrimaryKey(param.getEmployeeInterviewRecordsPrimaryKey());
        employeeUpdateCloudParam.setStartDate(param.getStartDate());
        employeeUpdateCloudParam.setInterviewTime(param.getInterviewTime());
        employeeUpdateCloudParam.setDepartmentKey(param.getDepartmentKey());
        employeeUpdateCloudParam.setDepartmentName(param.getDepartmentName());
        employeeUpdateCloudParam.setPositionKey(param.getPositionKey());
        employeeUpdateCloudParam.setPositionName(param.getPositionName());
        employeeUpdateCloudParam.setInterviewerKey(param.getInterviewerKey());
        employeeUpdateCloudParam.setInterviewerName(param.getInterviewerName());
        employeeUpdateCloudParam.setInterviewerStatus(param.getInterviewerStatus());
        employeeUpdateCloudParam.setInterviewComments(param.getInterviewComments());
        employeeUpdateCloudParam.setAnnexKey(param.getAnnexKey());
        employeeUpdateCloudParam.setRemark(param.getRemark());
        employeeUpdateCloudParam.setUpdateUserKey(YoukeyiSystemContext.getUserPrimaryKey());
        employeeUpdateCloudParam.setUpdateUserName(YoukeyiSystemContext.getUserName());
        return hrEmployeeInterviewRecordsCloudService.update(employeeUpdateCloudParam);
    }

    @Override
    public ResponseContent delete(BusinessEmployeeInterviewRecordsDeleteCloudParam param) {
        ResponseContent rc = new ResponseContent();
        String corpKey = YoukeyiSystemContext.getCorpPrimaryKey();
        if (StringUtils.isBlank(corpKey)) {
            rc.setErrorMessage(ResponseCodeEnum.TOKEN_INVALID.getMessage());
            return rc;
        }
        if (null == param || CollectionUtils.isEmpty(param.getEmployeeInterviewRecordsPrimaryKeys())) {
            rc.setErrorMessage(ResponseCodeEnum.PARAMETER_ILLEGAL.getMessage());
            return rc;
        }

        HrEmployeeInterviewRecordsDeleteCloudParam employeeDeleteCloudParam = new HrEmployeeInterviewRecordsDeleteCloudParam();
        employeeDeleteCloudParam.setEmployeeInterviewRecordsPrimaryKeys(param.getEmployeeInterviewRecordsPrimaryKeys());
        employeeDeleteCloudParam.setUpdateUserKey(YoukeyiSystemContext.getUserPrimaryKey());
        employeeDeleteCloudParam.setUpdateUserName(YoukeyiSystemContext.getUserName());
        return hrEmployeeInterviewRecordsCloudService.delete(employeeDeleteCloudParam);
    }
}
